package com.haitaoit.chengquan.module.center_service.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;

import com.haitaoit.chengquan.R;
import com.haitaoit.chengquan.base.BackCall;
import com.haitaoit.chengquan.view.MyListView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import java.util.List;

/**
 * Created by Administrator on 2016/10/17.
 */
public class CenterServiceAdapter extends BaseAdapter {
    private Context context;
    private BackCall backCall;
    private List list;
    private String type;

    public void setType(String type) {
        this.type = type;
    }

    public void setBackCall(BackCall backCall) {
        this.backCall = backCall;
    }

    public CenterServiceAdapter(Context context) {
        this.context = context;
    }

    public List getList() {
        return list;
    }

    public void setList(List list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.fragment_service_center_item, null);
            holder = new ViewHolder();
            ViewUtils.inject(holder, convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.service_item_ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CenterServiceAdapter.this.backCall.deal(R.id.service_item_ll, position);
            }
        });

        CenterServiceAdapter2 adapter2 = new CenterServiceAdapter2(context);
        holder.scrollview_listview.setAdapter(adapter2);
        holder.scrollview_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
                CenterServiceAdapter.this.backCall.deal(R.id.scrollview_listview, position);
            }
        });
        return convertView;
    }

    class ViewHolder {
        @ViewInject(R.id.service_item_ll)
        LinearLayout service_item_ll;
        @ViewInject(R.id.scrollview_listview)
        MyListView scrollview_listview;
    }
}
